package com.example.apigateway.common;

/**
 * @author ：Anitaxiaofeng
 * @description：
 * @create 2018-06-04
 **/
public class RestResponse<T> {

    private int code;
    private String msg;
    private T result;


    public static <T> RestResponse<T> success() {
        return new RestResponse<T>();
    }

    public static <T> RestResponse<T> success(T result) {
        RestResponse<T> response = new RestResponse<T>();
        response.setResult(result);
        return response;
    }

    public static <T> RestResponse<T> error(RestCode code) {
        return new RestResponse<T>(code.code,code.msg);
    }

    public RestResponse(int code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RestResponse() {
        this(RestCode.OK.code,RestCode.OK.msg);
    }

    public int getCode() {
        return code;
    }
    public void setCode(int code) {
        this.code = code;
    }
    public String getMsg() {
        return msg;
    }
    public void setMsg(String msg) {
        this.msg = msg;
    }
    public T getResult() {
        return result;
    }
    public void setResult(T result) {
        this.result = result;
    }


    @Override
    public String toString() {
        return "RestResponse [code=" + code + ", msg=" + msg + ", result=" + result + "]";
    }
}





